﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace WindowsHello
{
    public partial class WindowsFormDialog : Form
    {
        public String name="";
        public String begin = "Hello, ";
        public WindowsFormDialog()
        {
            this.KeyUp += new KeyEventHandler(OnKeyUp);
            this.KeyDown += new KeyEventHandler(OnKeyDown);
            
            InitializeComponent();
        }
        public void OnKeyUp(object sender, KeyEventArgs e)
        {
            //MessageBox.Show(e.KeyCode.ToString(), "Key Pressed!");

            if (e.KeyCode.Equals(ConsoleKey.Enter) 
                || e.KeyCode.Equals(ConsoleKey.Escape))
            {
                Close();
            }  

        }
        public void OnKeyDown(object sender, KeyEventArgs e)
        {
            //MessageBox.Show(e.KeyCode.ToString(), "Key Pressed!");

            if (e.KeyCode.Equals(ConsoleKey.Enter) 
                || e.KeyCode.Equals(ConsoleKey.Escape))
            {
                Close();
            }  

        }

        

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            this.name = textBox1.Text;
            if (this.name.Length != 0)
            {
                this.label2.Text = begin + this.name;
                this.label2.Visible = true;
                this.label2.Update();

            }
            else 
            {
                this.label2.Text = begin;
                this.label2.Visible = false;
                this.label2.Update();
            }
        }
    }
}
